﻿namespace SLClient.CustomerControls
{
    using SLClient.Extension;
    using SLClient.Infrastructure;
    using SLClient.ServiceAPI;
    using System;
    using System.Collections.ObjectModel;
    using System.Linq.Expressions;
    using System.Runtime.CompilerServices;

    public class TopWinerViewmodel : ViewModelBase
    {
        private ViwTopWinnerInfo _selectedTopWinnerInfo;

        public TopWinerViewmodel(PlayDataInfo playDataInfo)
        {
            this.ViwTopWinnerOrderDetail = playDataInfo.ViwTopInfos;
        }

        public TopWinerViewmodel(int catagory, string tag)
        {
            this.ViwTopWinnerOrderDetail = new ObservableCollection<ViwTopWinnerInfo>();
            this.Init(catagory, tag);
        }

        public void Init(int catagoryId, string tag)
        {
        }

        public void ShowDetail()
        {
            ServiceClient instance = WCFServicesUtil<ServiceClient>.GetInstance(ServiceType.ServiceAPI);
            instance.GetOrderDetailesCompleted += delegate (object obj, GetOrderDetailesCompletedEventArgs arg) {
                new OrderWindow(arg.Result).Show();
            };
            if (this.SelectedTopWinnerInfo != null)
            {
                instance.GetOrderDetailesAsync(this.SelectedTopWinnerInfo.OrderId, false);
            }
        }

        public ViwTopWinnerInfo SelectedTopWinnerInfo
        {
            get
            {
                return this._selectedTopWinnerInfo;
            }
            set
            {
                this._selectedTopWinnerInfo = value;
                base.Notify<ViwTopWinnerInfo>(() => this.SelectedTopWinnerInfo);
                //base.Notify<ViwTopWinnerInfo>(Expression.Lambda<Func<ViwTopWinnerInfo>>(Expression.Field(Expression.Constant(this, typeof(TopWinerViewmodel)), fieldof(TopWinerViewmodel._selectedTopWinnerInfo)), new ParameterExpression[0]));
            }
        }

        public ObservableCollection<ViwTopWinnerInfo> ViwTopWinnerOrderDetail { get; set; }
    }
}

